var api = require('../../../../api.js');
var utils = require('../../../../utils.js');
var WxParse = require('../../../../wxParse/wxParse.js');

var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userimg:'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1490916836,2885271316&fm=26&gp=0.jpg',

      windowHeight:0,
        order:[
            {'name':"个人信息",'img':'/page/casa/image/personal.png',"bind":"tomy_profile"},
            { 'name': "储值余额", 'img': '/page/casa/image/balance.png', "bind": "toyue"},
            { 'name': "优惠券", 'img': '/page/casa/image/yhq.png', "bind": "toyhq"},
            { 'name': "车险小金库", 'img': '/page/casa/image/cxxjk.png', "bind": "tobalance"},
            { 'name': "我的订单", 'img': '/page/casa/image/wddd.png', "bind": "tomyorder"},
            { 'name': "分享有礼", 'img': '/page/casa/image/ffyl.png', "bind": "toashare"},
        ]
    },
    // 跳到我的优惠券
    toyhq:function(){
        wx.navigateTo({
            url: '/pages/coupon/coupon',
        })
    },
    // 跳转到我的储值余额
    toyue:function(){
        wx.navigateTo({
            url: '/pages/balance/balance',
        })
    },
    // 跳到我的订单
    tomyorder:function(){
        wx.navigateTo({
            url: '/pages/order/order',
        })
    },
    // 跳转个人信息
    tomy_profile:function(){
        wx.navigateTo({
            url: '/page/casa/pages/my_profile/my_profile',
        })
    },
    // 跳转一键分享
    toashare:function(){
        wx.navigateTo({
            url: '/page/casa/pages/ashare/ashare',
        })
    },
    // 跳转储值余额
    tobalance:function(){
        var t = wx.getStorageSync("pages_user_user");
      var money = t.user_info.integral;
        wx.navigateTo({
          url: '/page/casa/pages/balance/balance?integral=' + money,
        })
    },

  loadData: function (e) {
    var a = this;
    a.setData({
      store: wx.getStorageSync("store")
    });
    var t = wx.getStorageSync("pages_user_user");
    t && a.setData(t), app.request({
      url: api.user.index,
      success: function (e) {
        console.log(e);
        0 == e.code && (a.setData(e.data), wx.setStorageSync("pages_user_user", e.data),
          wx.setStorageSync("share_setting", e.data.share_setting), wx.setStorageSync("user_info", e.data.user_info),
          console.log(e.data));
      }
    });
  },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
      let that = this;

      that.loadData();
        var menu = wx.getStorageSync("casa_navbar");
        menu.navs[3].active = true;
        that.setData({
            nav: menu.navs
        })
    //   app.request({
    //     url: api.casa.navbar,
    //     success: function (res) {
    //       that.setData({
    //         nav: res.data.navs
    //       })
    //     },
    //   })


      wx.getSystemInfo({
        success: function (res) {
          console.log(res.windowWidth);
          console.log(res.windowHeight);
          that.setData({
            windowHeight: res.windowHeight
          })
        },
      })

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})